package huawei;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Question7 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int N = sc.nextInt();
        sc.nextLine();
        ArrayList<Integer> ints = new ArrayList<>(N);
        for (int i = 0; i < N; i++) {
            ints.add(sc.nextInt());
        }

        ints.sort((e1, e2) -> {
            int abs1 = Math.abs(e1 - H);
            int abs2 = Math.abs(e2 - H);

            return abs1 == abs2 ? e1 - e2 : abs1 - abs2;
        });

        System.out.println(ints);
    }
}
